/*
 * loader.h
 *
 *  Created on: 2009-11-30
 *      Author: Bearice
 */

#ifndef LOADER_H_
#define LOADER_H_
#ifdef __cplusplus
extern "C" {
#endif //__cplusplus
struct avm_loader_status{
	int32 size;
	int32 left;
	char* ptr;
	char* data;
};
typedef struct avm_loader_status LOADER_STAT,*PLOADER_STAT;
struct avm_constant{
	uint32 tag;
	uint32 size;
	char* data;
};
typedef struct avm_constant A_CONSTANT,*P_CONSTANT;
struct avm_section{
	uint32 tag;
	uint32 size;
	char* data;
};
typedef struct avm_section A_SECTION,*P_SECTION;
struct avm_code{
	uint32 magic;
	uint32 version;
	uint32 entrypoint;
	uint32 constant_count;
	A_CONSTANT* constants;
	uint32 section_count;
	A_SECTION* sections;
};
typedef struct avm_code A_CODE,*P_CODE;
extern P_CODE avm_load_code(uint8* data,uint32 len);
extern uint32 avm_loader_init(PLOADER_STAT stat, uint8* data, uint32 size);
extern char* consumeBytes(PLOADER_STAT stat,int32 len);
extern uint64 readUInt64(PLOADER_STAT stat);
extern  int64 readInt64(PLOADER_STAT stat);
extern uint32 readUInt32(PLOADER_STAT stat);
extern  int32 readInt32(PLOADER_STAT stat);
extern uint16 readUInt16(PLOADER_STAT stat);
extern  int16 readInt16(PLOADER_STAT stat);
extern uint8  readUInt8(PLOADER_STAT stat);
extern  int8  readInt8(PLOADER_STAT stat);
extern uint64 avm_ntohll(uint64);
extern uint32 avm_ntohl (uint32);
extern uint16 avm_ntohs (uint16);
#ifdef __cplusplus
}
#endif //__cplusplus
#endif /* LOADER_H_ */
